package com.yan.ems.exception;

import com.yan.ems.pojo.vo.Result;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

//@RestControllerAdvice
public class GlobalExceptionHandler {
	@ExceptionHandler({ForecastException.class, FileEmptyException.class})
	public Result<Void> functionExceptionHandler(Exception e, HttpServletRequest request) {
		// todo 可以具体细分
		return Result.error();
	}

	@ExceptionHandler(LoginFirstException.class)
	public Result<Void> loginFirstExceptionHandler(LoginFirstException e, HttpServletRequest request) {
		Result<Void> result = new Result<>();
		result.setCode(HttpStatus.UNAUTHORIZED.value());
		result.setMsg("请先登录");
		return result;
	}

	@ExceptionHandler(Exception.class)
	public Result<Void> exceptionHandler(Exception e, HttpServletRequest request) {
		Result<Void> result = new Result<>();
		result.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
		result.setMsg(e.getMessage());
		return result;
	}
}
